<!DOCTYPE html>
<html lang="zh-cn">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<meta name="renderer" content="webkit">
	<title></title>
	<link rel="stylesheet" href="/public/admin/css/pintuer.css">
	<link rel="stylesheet" href="/public/admin/css/admin.css">
	<script src="/public/admin/js/jquery.js"></script>
	<script src="/public/admin/js/pintuer.js"></script>
</head>

<body>
	<div class="panel admin-panel">
		<div class="panel-head"><strong class="icon-reorder">评论列表</strong> <a href=""
				style="float:right; display:none;">添加字段</a></div>
		<div class="padding border-bottom">
			<ul class="search" style="padding-left:10px;">
				<li> <a class="button border-main icon-plus-square-o" href="/admin/admin/add" aria-disabled="true"> 添加评论</a> </li>
				<li>
					<form action="" method="get">
						<input type="text" placeholder="请输入搜索标题关键字" name="search" class="input"
							style="width:250px; line-height:17px;display:inline-block" />
						<button class="button border-main icon-search">搜索</button>
					</form>
				</li>
			</ul>
		</div>
		<table class="table table-hover text-center">
			<tr>
				<th width="100" style="text-align:left; padding-left:20px;">ID</th>
				<th>用户名</th>
				<th>文章标题</th>
				<th>文章图片</th>
				<th>评论内容</th>
				<th>评论时间</th>
				<th>评论状态</th>
			</tr>
			<!-- ejs的模板引擎 -->
			<% data.forEach(item=>{ %>
				<tr>
					<td><%= item.id%></td>
					<td><%= item.username%></td>
					<td><%= item.title%></td>
					<td><img style="height: 100px;" src="<%= item.img%>" alt="评论图片"></td>
					<td><%- item.text%></td>
					<td><%=item.time%></td>
					<td>
						<select name="" id="" onchange="changestatus(this,`<%= item.id%>`,`<%= item.status%>`)">
							<option <%= item.status == 0 ? 'selected' : '' %> value="0">未审核</option>
							<option <%= item.status == 1 ? 'selected' : '' %>  value="1">审核通过</option>
							<option <%= item.status == 2 ? 'selected' : '' %> value="2">审核失败</option>
						</select2
					</td>
				</tr>
			<% }) %>

			<tr>
					<td colspan="8">
						<div class="pagelist"> 
							<%- show%>
						</div>
					</td>
				</tr>
		
	</table>
	</div>
	</form>
	<script>
		function changestatus(obj,id,status){
			// 获取状态值
			let statusVal =$(obj).val();
			$.get("/admin/comment/ajax_status",{id:id,status:statusVal},function(data){
				if(data == 1){
					alert("修改成功");
				}else{
					alert("修改失败");
				}
			});
		}
	</script>
</body>

</html>